from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-18 14:03:10.912097
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 18, Dec, 2021
Time: 14:03:16
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.5327
Nobs: 509.000 HQIC: -47.9877
Log likelihood: 5877.38 FPE: 1.07598e-21
AIC: -48.2811 Det(Omega_mle): 9.03145e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.353696 0.079041 4.475 0.000
L1.Burgenland 0.100485 0.043865 2.291 0.022
L1.Kärnten -0.115431 0.022585 -5.111 0.000
L1.Niederösterreich 0.181499 0.090941 1.996 0.046
L1.Oberösterreich 0.123962 0.092081 1.346 0.178
L1.Salzburg 0.283266 0.047176 6.004 0.000
L1.Steiermark 0.022981 0.060907 0.377 0.706
L1.Tirol 0.108853 0.049183 2.213 0.027
L1.Vorarlberg -0.081326 0.043342 -1.876 0.061
L1.Wien 0.027743 0.082844 0.335 0.738
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.012332 0.174793 0.071 0.944
L1.Burgenland -0.048530 0.097004 -0.500 0.617
L1.Kärnten 0.035545 0.049944 0.712 0.477
L1.Niederösterreich -0.207372 0.201108 -1.031 0.302
L1.Oberösterreich 0.458497 0.203630 2.252 0.024
L1.Salzburg 0.313580 0.104326 3.006 0.003
L1.Steiermark 0.107387 0.134690 0.797 0.425
L1.Tirol 0.315417 0.108764 2.900 0.004
L1.Vorarlberg 0.011244 0.095848 0.117 0.907
L1.Wien 0.011831 0.183203 0.065 0.949
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.219479 0.040273 5.450 0.000
L1.Burgenland 0.092137 0.022350 4.122 0.000
L1.Kärnten -0.005228 0.011507 -0.454 0.650
L1.Niederösterreich 0.225359 0.046336 4.864 0.000
L1.Oberösterreich 0.164132 0.046917 3.498 0.000
L1.Salzburg 0.037623 0.024037 1.565 0.118
L1.Steiermark 0.028682 0.031033 0.924 0.355
L1.Tirol 0.078078 0.025059 3.116 0.002
L1.Vorarlberg 0.055964 0.022083 2.534 0.011
L1.Wien 0.104938 0.042210 2.486 0.013
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162281 0.039666 4.091 0.000
L1.Burgenland 0.043364 0.022014 1.970 0.049
L1.Kärnten -0.013349 0.011334 -1.178 0.239
L1.Niederösterreich 0.154445 0.045638 3.384 0.001
L1.Oberösterreich 0.337277 0.046210 7.299 0.000
L1.Salzburg 0.100311 0.023675 4.237 0.000
L1.Steiermark 0.111508 0.030566 3.648 0.000
L1.Tirol 0.090615 0.024682 3.671 0.000
L1.Vorarlberg 0.054695 0.021751 2.515 0.012
L1.Wien -0.041798 0.041575 -1.005 0.315
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.147313 0.075484 1.952 0.051
L1.Burgenland -0.036659 0.041891 -0.875 0.382
L1.Kärnten -0.036481 0.021568 -1.691 0.091
L1.Niederösterreich 0.133553 0.086848 1.538 0.124
L1.Oberösterreich 0.182529 0.087938 2.076 0.038
L1.Salzburg 0.256138 0.045053 5.685 0.000
L1.Steiermark 0.078912 0.058166 1.357 0.175
L1.Tirol 0.133024 0.046970 2.832 0.005
L1.Vorarlberg 0.105952 0.041392 2.560 0.010
L1.Wien 0.038261 0.079116 0.484 0.629
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.076484 0.059714 1.281 0.200
L1.Burgenland 0.017226 0.033139 0.520 0.603
L1.Kärnten 0.050995 0.017062 2.989 0.003
L1.Niederösterreich 0.182480 0.068704 2.656 0.008
L1.Oberösterreich 0.333212 0.069565 4.790 0.000
L1.Salzburg 0.051411 0.035641 1.442 0.149
L1.Steiermark -0.003649 0.046014 -0.079 0.937
L1.Tirol 0.125906 0.037157 3.389 0.001
L1.Vorarlberg 0.059713 0.032744 1.824 0.068
L1.Wien 0.107515 0.062587 1.718 0.086
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169807 0.072400 2.345 0.019
L1.Burgenland 0.011695 0.040179 0.291 0.771
L1.Kärnten -0.061115 0.020687 -2.954 0.003
L1.Niederösterreich -0.109358 0.083299 -1.313 0.189
L1.Oberösterreich 0.231123 0.084344 2.740 0.006
L1.Salzburg 0.039752 0.043212 0.920 0.358
L1.Steiermark 0.264100 0.055789 4.734 0.000
L1.Tirol 0.489779 0.045050 10.872 0.000
L1.Vorarlberg 0.070134 0.039700 1.767 0.077
L1.Wien -0.103159 0.075883 -1.359 0.174
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.141576 0.080114 1.767 0.077
L1.Burgenland -0.012205 0.044461 -0.275 0.784
L1.Kärnten 0.063102 0.022891 2.757 0.006
L1.Niederösterreich 0.174801 0.092175 1.896 0.058
L1.Oberösterreich -0.083156 0.093331 -0.891 0.373
L1.Salzburg 0.224307 0.047817 4.691 0.000
L1.Steiermark 0.136655 0.061734 2.214 0.027
L1.Tirol 0.054174 0.049851 1.087 0.277
L1.Vorarlberg 0.141199 0.043931 3.214 0.001
L1.Wien 0.163153 0.083969 1.943 0.052
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.457246 0.044552 10.263 0.000
L1.Burgenland 0.000179 0.024725 0.007 0.994
L1.Kärnten -0.014217 0.012730 -1.117 0.264
L1.Niederösterreich 0.181568 0.051260 3.542 0.000
L1.Oberösterreich 0.256756 0.051902 4.947 0.000
L1.Salzburg 0.019277 0.026591 0.725 0.469
L1.Steiermark -0.009055 0.034331 -0.264 0.792
L1.Tirol 0.073975 0.027722 2.668 0.008
L1.Vorarlberg 0.057114 0.024430 2.338 0.019
L1.Wien -0.021369 0.046696 -0.458 0.647
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.030126 0.095257 0.157860 0.142460 0.068377 0.081417 0.015900 0.211187
Kärnten 0.030126 1.000000 -0.031813 0.135297 0.051873 0.076058 0.455710 -0.078517 0.101308
Niederösterreich 0.095257 -0.031813 1.000000 0.286069 0.103966 0.256536 0.052359 0.145695 0.252892
Oberösterreich 0.157860 0.135297 0.286069 1.000000 0.200049 0.287254 0.160994 0.129696 0.197502
Salzburg 0.142460 0.051873 0.103966 0.200049 1.000000 0.122932 0.061660 0.111306 0.072121
Steiermark 0.068377 0.076058 0.256536 0.287254 0.122932 1.000000 0.133743 0.090858 0.012513
Tirol 0.081417 0.455710 0.052359 0.160994 0.061660 0.133743 1.000000 0.065199 0.128854
Vorarlberg 0.015900 -0.078517 0.145695 0.129696 0.111306 0.090858 0.065199 1.000000 -0.005619
Wien 0.211187 0.101308 0.252892 0.197502 0.072121 0.012513 0.128854 -0.005619 1.000000